package com.parkcar.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.parkcar.R;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import util.BaseTools;
import util.Constrants;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{
	
	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	
    private IWXAPI api;
	private TextView result_text;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);
    	api = WXAPIFactory.createWXAPI(this, "wxac2843ffa600c3d2");
        api.handleIntent(getIntent(), this);
		result_text = (TextView) this.findViewById(R.id.result_title);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		Log.e("测试", "onPayFinish, errCode = " + resp.errCode);
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			String string="";
			result_text = (TextView) this.findViewById(R.id.result_title);
			switch (resp.errCode){
				case 0://成功
					result_text.setText("支付成功");
					Intent mIntent = new Intent();
					mIntent.setAction( Constrants.RECHARG_SUCCESS);
					sendBroadcast(mIntent);
					break;
				case -1:
					result_text.setText("支付失败："+ (BaseTools.isValueEmpty(resp.errStr)?"未知原因":resp.errStr));
					break;
				case -2:
					result_text.setText("支付失败：您已取消支付");
					break;
			}
		}
	}
	public void dissmiss(View view){
		finish();
	}
}